package application.Mediatiors
{
	import VCs.PlayBtnVC;
	
	import application.BallFacade;
	import application.Proxies.StreamWritePxy;
	
	import org.gof.application.BaseAppFacade;
	import org.gof.application.BaseMediator;
	import org.gof.application.SetByAppNS;
	
	import flash.display.DisplayObjectContainer;
	import flash.display.DisplayObject;
	import flash.display.SimpleButton;
	import flash.text.TextField;

	use namespace SetByAppNS;
	public class PlayBtnMed extends BaseMediator
	{
		private static const START_TEXT:String = "START";
		private static const RESUME_TEXT:String = "RESUME";
		private static const PAUSE_TEXT:String = "PAUSE";

		private var _vc:PlayBtnVC;
		private var _tf:TextField;
		private var _btn:SimpleButton;
		
		private var app:BallFacade;
		
		public var data:StreamWritePxy;
		
		public function PlayBtnMed()
		{
	
		}
		
		SetByAppNS override function set application(a:BaseAppFacade):void
		{
			super.application = a;
			app = _app as BallFacade;
		}
		
		public function set viewPort(vp:DisplayObjectContainer):void
		{
			_vc = new PlayBtnVC(vp);	
			_vc.clickCallBack = handleBtnClick;
			var tempDO:DisplayObject = vp.getChildByName("playBtn_mc");
			_btn = (vp as Object).play_btn;
			
			_tf = (vp as Object).play_tf;
			_tf.mouseEnabled = false;
			_tf.text = START_TEXT;
			
				
		}
				
		private function handleBtnClick():void
		{
			trace("PlayBtnMed.handleBtnClick");
			if (data.isStarted)
			{
				if (data.isPlayingNotPaused)
				{
					app.streamCmdCtr.pauseCmd.execute();
					_tf.text = RESUME_TEXT;
				}
				else
				{
					app.streamCmdCtr.resumeCmd.execute();
					_tf.text = PAUSE_TEXT;
				}
				
			}
			else
			{
				app.streamCmdCtr.startCmd.execute();
				_tf.text = PAUSE_TEXT;
			}
			
			
		}
	}
}